package com.boot.security.server.utils.mffl.WecahtPayUtil;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Map;

import org.apache.commons.io.IOUtils;

import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;


/*系统配置信息*/
public class OurWxPayConfig implements WXPayConfig {


    private String AppID;
    private String AppSecret;
    private String MchID;
    private String Key;


    /*加载证书*/
    private byte[] certData;

    public OurWxPayConfig(){
        try {
            InputStream inputstream = Thread.currentThread().getContextClassLoader().getResourceAsStream("apiclient_cert.p12");
            this.certData = IOUtils.toByteArray(inputstream);
            inputstream.close();

            Yaml yaml = new Yaml();
            InputStream yamlinputstream = Thread.currentThread().getContextClassLoader().getResourceAsStream("application-prod.yml");
            Map<String, Object> map = yaml.loadAs(yamlinputstream, Map.class);
            AppID = ((Map<String, Object>) map.get("Pay")).get("AppID").toString();
            AppSecret = ((Map<String, Object>) map.get("Pay")).get("AppSecret").toString();
            MchID = ((Map<String, Object>) map.get("Pay")).get("MchID").toString();
            Key = ((Map<String, Object>) map.get("Pay")).get("Key").toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //公众号AppID
    public String getAppID() {
        // TODO Auto-generated method stub
        //return "wx04bd786c07d2956c";
        return AppID;
    }

    public String getAppSecret() {
        // TODO Auto-generated method stub
        //return "afbf19c3f2d9dd0040921f30302197b8";
        return AppSecret;
    }


    //商户号
    public String getMchID() {
        // TODO Auto-generated method stub
        //return "1513625081";
        return MchID;

    }


    //商户号Key
    public String getKey() {
        // TODO Auto-generated method stub
        //return "ez7og9s3780royhrq6mcql0k4fkreoly";
        return Key;

    }


    //证书流
    public InputStream getCertStream() {
        // TODO Auto-generated method stub
        return new ByteArrayInputStream(this.certData);
    }


    //连接超时时间
    public int getHttpConnectTimeoutMs() {
        // TODO Auto-generated method stub
        return 0;
    }


    //读取数据超时时间
    public int getHttpReadTimeoutMs() {
        // TODO Auto-generated method stub
        return 0;
    }

}
